package fe.pong.tennis.screens;

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import motion.easing.Elastic;
import motion.easing.Expo;
import motion.easing.Quad;
import motion.Actuate;
import openfl.Assets;

class PresentationScreen extends Screen {

	private var gameLogo: Sprite;
	private var companyLogo: Sprite;
	private var sound: Sound; 
	private var intro: SoundChannel;
	
	public function new () {
		
		super ();
		
		var logoBitmap = new Bitmap (Assets.getBitmapData ("assets/pangrockerlogo.png"));
		var companyBitmap = new Bitmap(Assets.getBitmapData("assets/fichinlogo.png"));
		//logoBitmap.x = - logoBitmap.width / 2;
		//logoBitmap.y = - logoBitmap.height / 2;
		logoBitmap.smoothing = true;
		
		gameLogo = new Sprite ();
		companyLogo = new Sprite ();
		gameLogo.addChild (logoBitmap);
		companyLogo.addChild (companyBitmap);
		
		gameLogo.alpha = 0;
		gameLogo.scaleX = 0;
		gameLogo.scaleY = 0;
		gameLogo.x = (stage.stageWidth - logoBitmap.width) / 2;
		gameLogo.y = (stage.stageHeight - logoBitmap.height) / 2;
		
		companyLogo.alpha = 0;
		companyLogo.x = 0;
		companyLogo.y = 0;
		companyLogo.width = stage.stageWidth;
		companyLogo.height = stage.stageHeight;
		
		addChild (gameLogo);
		addChild (companyLogo);
		
		Actuate.tween (companyLogo, 5, { alpha: 1 } ).ease(Quad.easeOut);
		Actuate.tween (companyLogo, 5, { alpha: 0 },false ).ease(Quad.easeOut).delay(2).onComplete(showGameLogo);
		
	}
	
	public function showGameLogo () {
		sound = Assets.getSound('assets/intro.mp3');
		sound.play(0,5,new SoundTransform());
		//Actuate.tween (gameLogo, 2, { alpha: 1 } );
		//Actuate.tween (gameLogo, 4, { scaleX: 1, scaleY: 1 } ).delay (0.4).ease (Elastic.easeOut);
		Actuate.tween (gameLogo, 2, { alpha: 1, scaleX: 1, scaleY: 1} ).ease (Elastic.easeOut);
		//Actuate.tween (gameLogo, 5, { x: 200, y: 100 } ).;
	}	
}